package com.enlorenz.core.channel.socket.common.writer;

import com.enlorenz.common.util.CodeUtils;

/**
 * 抽象的加头写出者
 * @author MAC
 */
public abstract class AbstractLengthAppendWriter implements IWriter{
	//数字的长度
	private Integer numLength=8;
	@Override
	public void write(byte[] data) throws Exception {
		byte [] lenbytes=CodeUtils.getIntegerBytes(data.length, numLength);
		byte [] out=CodeUtils.gatherBytes(lenbytes,data);
		writeHeadMsg(out);
	}
	
	protected abstract void writeHeadMsg(byte [] fullData) throws Exception;
	
	public void setNumLength(Integer numLength) {
		this.numLength = numLength;
	}
}
